<?php
/**
 * @package		Joomla.Site
 * @subpackage	mod_search
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;
?>
<div id="ctform">
<form method="post" name="f-contact" id="f-contact" class="f-contact" enctype="multipart/form-data">
<fieldset>
<div class="w144"><label>Navn:</label><br> <input type="text" value="" id="ct_name" name="ct_name"></div>
<div class="w144r"><label>Email:</label><br> <input type="text" value="" id="ct_email" name="ct_email"></div>
<div><label>Besked:</label><br> <textarea  cols="" rows="" id="ct_desc" name="ct_desc"></textarea></div>
<div class="bnt-send"><a onclick="jQuery('#f-contact').submit();">SEND</a></div>
<?php echo JHtml::_('form.token');?>
</fieldset>
</form>
</div>
<?php                        	       
$input_name = JText::_( 'Indtast din navn' );
$input_email = JText::_( 'Indtast din email' );
$input_description = JText::_( 'Indtast din besked' );
?>                        
 <script type="text/javascript">                   
jQuery(document).ready(function(jQuery) {
	jQuery.validator.addMethod('postalcode', function (value) { 
		if(value=='') return true;	
		return /^\d{4}$/.test(value); 
	   }, '');
		jQuery("#postcode").mask("9999",{placeholder:""});  
		
		jQuery("#f-contact").validate(
			{
				errorPlacement: function(error, element) {			
			},
			invalidHandler: function(form, validator) {
			  var errors = validator.numberOfInvalids();
			if (errors) {
                //$('#alert').html(validator['errorList'][0]['message']);
				jQuery('#alert').html(validator['errorList'][0]['message']);
    			jQuery('#backoverlay').show();
    			jQuery('#show_popup').show();
            	jQuery('#f_focus').html(validator['errorList'][0]['element'].name);
				validator['errorList'][0]['element'].focus();
				
			  } else {
			  }
			},
			rules: {
				ct_name:{
					required: true,
				},			
				ct_email: {
					required: true,
					email:true
				},
				ct_desc:{
					required: true,
				}
			},
			messages: {
				ct_name: "<?php echo $input_name; ?>",
				ct_email: "<?php echo $input_email; ?>",
				ct_desc: "<?php echo $input_description; ?>"
			},
      		submitHandler: function() { 
			
			var ct_name = jQuery('#ct_name').val();
			var ct_email = jQuery('#ct_email').val();
			var ct_desc = jQuery('#ct_desc').val();
				/*
			 	jQuery.ajax({
				type: "POST",
				url: "index.php?option=com_contact&task=quickcontact&layout=ajax",				
				dataType: "json",
				data: { ct_name: ct_name , ct_email : ct_email , ct_desc : ct_desc },
				success: function(msg){
					alert(msg);
						//jQuery('.contact-form').html(msg);
				}});
				*/
				jQuery.ajax({
				type: "POST",
				url: "index.php?option=com_contact&task=quickcontact&tmpl=ajax",				
				dataType: "json",
				data: { ct_name: ct_name , ct_email : ct_email , ct_desc : ct_desc },
				success: function(data){
					//alert('succ');
					jQuery('#ctform').addClass('address');
					jQuery('#ctform').html(data);
					
				},complete: function(data){
					jQuery('#ctform').addClass('address');
					jQuery('#ctform').html(data.responseText);
				}
				
				
				});
				//alert('222');
			}
		});
        close_popup=function(){		
			var fel=jQuery('#f_focus').html();
            jQuery('#backoverlay').hide();
    		jQuery('#show_popup').hide();
    		jQuery('#' + fel ).focus();		
      };
      
      
	});
</script>


